from django.contrib.auth.models import Group
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet

from apps.meiduo_mall_admin.serializers.admins import AdminSerializer
from apps.meiduo_mall_admin.serializers.group import GroupSerializer
from apps.meiduo_mall_admin.utils import PageNum
from apps.users.models import User


class AdminView(ModelViewSet):
    """获取管理员用户列表数据"""
    # 定义序列化器
    serializer_class = AdminSerializer
    # 获取管理员用户
    queryset = User.objects.filter(is_staff=True)
    # 分页
    pagination_class = PageNum


class AdminSimpleAPIView(APIView):
    """获取分组表数据"""
    def get(self,request):
        # 获取模型数据
        pers = Group.objects.all()
        # 使用序列化器传值
        serializer = GroupSerializer(pers,many=True)
        # 返回数据
        return Response(serializer.data)